********************************************************************************
* Exporting table for multi-country COVID paper (BGD3 sample)
* last updated: 2020-10-22
* Salim Benhachmi
********************************************************************************

clear all
use "$da/BGD3", clear

********************************************************************************

* SES Status
preserve
keep hhid hh_consumption
duplicates drop
sum hh_consumption, detail
gen higher_ses = (hh_consumption >= `r(p50)')
gen lower_ses = (hh_consumption < `r(p50)')
drop hh_consumption
tempfile ses
save `ses'
restore
merge m:1 hhid using `ses', nogen

gen full_sample = 1

********************************************************************************

* Drop in employment
gen drop_empl = (lm14_wage_or_not == 1 & ec_q11 != 1)

* Drop in income
gen drop_inc = .
replace drop_inc = 0 if ec_q12_wage != . & ec_q15_pastmonth != .
replace drop_inc = 0 if ec_q18_monthprofit != . & ec_q21_profitlast != .
replace drop_inc = 1 if ec_q15_pastmonth < ec_q12_wage & ec_q12_wage != . & ///
	ec_q15_pastmonth != .
replace drop_inc = 1 if ec_q21_profitlast < ec_q18_monthprofit & ///
	ec_q18_monthprofit != . & ec_q21_profitlast != .

* Reduced access to markets
gen mkts_clsd = (ec_q2_buying_3 == 1)

* Healthcare access delayed
* N/A

* Missed or reduced meals
gen fd_ins = (ec_q4_mechanism_2 == 1)

* Received NGO or Government Support
gen ngo_gov_sprt = (ec_q4_mechanism_7 == 1)

********************************************************************************

keep if covid_sample == 1

svyset cluster2 [pw=hh_weight_covid], singleunit(scaled)

local subgroups higher_ses lower_ses full_sample
local indicators drop_empl drop_inc mkts_clsd fd_ins ngo_gov_sprt

foreach subgroup of local subgroups {
	
	foreach ind of local indicators {
		svy: mean `ind' if `subgroup' == 1
		matrix b = r(table)
		loc mean_`ind'_`subgroup' : di %10.2fc b[1,1]
	}
}

sum covid_sample if higher_ses == 1
loc mean_n_higher_ses :  di %10.0fc r(N)
sum covid_sample if lower_ses == 1
loc mean_n_lower_ses :  di %10.0fc r(N)
sum covid_sample if full_sample == 1
loc mean_n_full_sample :  di %10.0fc r(N)

clear
set obs 3

local indicators drop_empl drop_inc mkts_clsd fd_ins ngo_gov_sprt n

foreach ind of local indicators {	
	gen mean_`ind' = ""
}

foreach ind of local indicators {	
	replace mean_`ind' = "`mean_`ind'_full_sample'" in 1
}

foreach ind of local indicators {	
	replace mean_`ind' = "`mean_`ind'_lower_ses'" in 2
}

foreach ind of local indicators {	
	replace mean_`ind' = "`mean_`ind'_higher_ses'" in 3
}

gen mean_hlth_care_denied = ""

order mean_drop_inc mean_drop_empl mean_mkts_clsd mean_hlth_care_denied ///
	mean_fd_ins mean_ngo_gov_sprt mean_n

export excel using "$dtab/Main Table.xlsx", sheetmodify cell(B12)

********************************************************************************
